package com.zh.webflux.log;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 用户登录记录器
 * 记录用户的登录
 * 异步保存
 *
 * @author ZH
 * @date 19:50 2021/11/5
 */
@Slf4j
@AllArgsConstructor
@Component
public class OperationLogRecorder {

    /**
     * 记录web用户登录日志
     *
     * @param remoteHost
     */
    public void loginLog(String remoteHost, String username) {
        String operation = String.format("Web端用户(%s)登录成功", username);
        OperateLogRecord logRecord = new OperateLogRecord(remoteHost, operation, "/login");

        log.info("【用户登录】：remoteHost = {}, operation = {}", remoteHost, operation);
    }

    /**
     * 记录web用户访问日志
     *
     * @param remoteHost
     * @param operation
     * @param accessUri
     * @param queryParams
     */
    public void accessLog(String remoteHost, String operation, String accessUri, String queryParams) {
        OperateLogRecord logRecord = new OperateLogRecord(remoteHost, operation, accessUri, queryParams);
        log.info("【接口访问】：remoteHost = {}, operation = {}, accessUri = {}, queryParams = {}",
                remoteHost, operation, accessUri, queryParams);
    }

}
